package store

import (
	"gvm/instructions/base"
	"gvm/rtda"
)

type ASTORE struct {
	base.Index8Instruction
}

func (self *ASTORE) Execute(jFrame *rtda.JFrame) {
	_astore(jFrame, self.Index)
}

type ASTORE_0 struct {
	base.NoOperandsInstruction
}

func (self *ASTORE_0) Execute(jFrame *rtda.JFrame) {
	_astore(jFrame, 0)
}

type ASTORE_1 struct {
	base.NoOperandsInstruction
}

func (self *ASTORE_1) Execute(jFrame *rtda.JFrame) {
	_astore(jFrame, 1)
}

type ASTORE_2 struct {
	base.NoOperandsInstruction
}

func (self *ASTORE_2) Execute(jFrame *rtda.JFrame) {
	_astore(jFrame, 2)
}

type ASTORE_3 struct {
	base.NoOperandsInstruction
}

func (self *ASTORE_3) Execute(jFrame *rtda.JFrame) {
	_astore(jFrame, 3)
}

func _astore(frame *rtda.JFrame, index uint) {
	val := frame.OperandStack().PopRef()
	frame.LocalVars().SetRef(index, val)
}
